//
//  GameCommentsTableViewCell.m
//  gamebox_qpp
//
//  Created by 赵隆杰 on 2022/2/10.
//

#import "GameCommentsTableViewCell.h"
#import "GamePublishCommentsViewController.h"

@interface GameCommentsTableViewCell ()

@property (weak, nonatomic) IBOutlet UIImageView *userImage;
@property (weak, nonatomic) IBOutlet UILabel *userNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UIButton *reportBtn;
@property (weak, nonatomic) IBOutlet UIButton *commentsBtn;


@end

@implementation GameCommentsTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.userImage.layer.cornerRadius = self.userImage.height/2;
    self.userImage.layer.masksToBounds = YES;
}

- (void)setModel:(CommentsModel *)model
{
    _model = model;
    UserInfoModel *user = model.iosUser;
    [self.userImage yy_setImageWithURL:[NSURL URLWithString:[LocalData getHeadStr]] placeholder:[UIImage imageNamed:@"appicon"]];
    if (user.nickname.length) {
        self.userNameLabel.text = user.nickname;
    } else {
        if (user.account.length) {
            self.userNameLabel.text = user.account;
        } else {
            self.userNameLabel.text = @"奇葩用户";
        }
    }
    self.contentLabel.text = [NSString stringWithFormat:@"%@", model.content];
    NSString *timeStr = [NSDate timeStringToInterval:model.time.doubleValue dataFormat:@"yyyy-MM-dd HH:mm"];
    self.timeLabel.text = [NSString stringWithFormat:@"%@", timeStr];
}
- (IBAction)btnAction:(UIButton *)sender {
    if (![LocalData fetchUserInfo]) {
        [[AppLogic sharedInstance] presentLoginVC];
        return;
    }
    if (sender.tag == 0) {
        //评论
        [self enterComments];
    } else {
        //举报
        [self report];
    }
    if (self.btnActionBlock) {
        self.btnActionBlock(sender.tag, _model);
    }
}

// 举报
- (void)report
{
    
    
}
//发帖
- (void)enterComments
{
    GamePublishCommentsViewController *vc = [[GamePublishCommentsViewController alloc] init];
    vc.gameId = _model.gameId;
//    VHWeakSelf
//    vc.editCompleteBlock = ^(BOOL result) {
//        VHStrongSelf
//        [self refreshAfterLogin];
//    };
    [[UIWindow currentViewController].navigationController pushViewController:vc animated:YES];
}

@end
